/***************** Modification History ***********************************
   @doc
   @module review.c - Application Review functions |
   @end

$Log: /SoftPay/SPK2SIM/Source/Batch/review.c $
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/

#include <project.h>

#ifdef BATCH_DEFINED

#define VSREVIEW_C

#include <aclconio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dbmgr.h>
#include <stdio.h>
#include <applidl.h>
#include <acldev.h>
#include <aclstr.h>
#include <ascii.h>
#include <svctxo.h>
#include <string.h>
#include <actutil.h>

/** /#define DEBUG_VSREVIEW*/
#ifdef DEBUG_VSREVIEW
#define DEBUG_95
#endif

#include <define.h>
#include <transact.h>
#include <bdt.h>
#include <cdt.h>
#include <cst.h>
#include <dct.h>
#include <hdt.h>
#include <tblutil.h>
#include <lct.h>
#include <tct.h>
#include <trt.h>
#include <mit.h>
#include <tran.h>
#include <fields.h>
#include <menufunc.h>
#include <menus.h>
#include <ui.h>
#include <passwd.h>
#include <comm.h>
#include <spdebug.h>
#include <oper.h>
#include <init.h>
#include <msg.h>
#include <msgfuncs.h>
#include <clerk.h>
#include <msgclrk.h>
#include <udt.h>
#include <print.h>
#include <form.h>
#include <pform.h>
#include <entry.h>
#include <review.h>
#include <table.h>
#include <funcs.h>
#include <funcids.h>
#include <date.h>
#include <rcptcmpt.h>
#include <rcptsegs.h>
#include <codesec.h>
#include <batch.h>
#include <pbatch.h>
#include <batmsg.h>
#include <logo.h>
#include <multilng.h>
#include <sizes.h>
#include <util.h>
#include <gds.h>
#include <mdlfuncs.h>
#include <format.h>
#include <amount.h>
#include <tip.h>
#include <tblutil.h>


#define CHOICE_INV    1
#define CHOICE_ACCT   2

#define KEY_ADJ     1
#define KEY_PREV    2
#define KEY_NEXT    3
#define KEY_EXIT    4       /* express tip */

static  signed int inSelect;

/*********************************************************************************************
* @func static int | inBatchReview |
*
*           Initiate batch review process
*
* @parm TRANSACTION_OBJECT *    | pobTran |
*
* @rdesc Return values.
*
* @flag int    |    - VS_ERR
*                   - VS_SUCCESS
* @end
**********************************************************************************************/

static int inBatchReview(TRANSACTION_OBJECT* pobTran) {
    int inResult,
    inOperationCode;
    BATCH_KEY srBatchKey;

    inOperationCode = BATCH_REVIEW_OPERATION;
    vdSGOpCode(inOperationCode);

    if (fBatchEmpty(pobTran, VS_FALSE) == VS_TRUE) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, ERROR_MSG);
        return (VS_ERR);
    }

    do {
        do {
            vdDispMsgAt(SUMMARY_REVIEW_MSG15, obDisp.inHomeCol, obDisp.inTitleLine, CLR_EOL);
            inResult = inRetrieveBatch(pobTran);
            if (inResult == VS_ABORT) {
                vdSGErrorMessage(0L);
                return(VS_ESCAPE);
            }
        } while (inResult != VS_SUCCESS);

        memcpy(&srBatchKey, &pobTran->srBKey, sizeof(BATCH_KEY));

        do {
            int inKeyPress;

            vdDispMsgAt(SUMMARY_REVIEW_MSG15, obDisp.inHomeCol, obDisp.inTitleLine, CLR_EOL);
            inKeyPress = inDisplayReviewRec(pobTran, pchGetMsg(REVIEW_OPTION_MSG5x), 4);
            inResult = inGetReviewOption(pobTran, &srBatchKey, inKeyPress);
        } while (inResult != VS_ESCAPE);
    } while (1);
}

/*********************************************************************************************
* @func static int | inRetrieveBatch |
*
*       This function prompts user to choose a search path.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inRetrieveBatch(TRANSACTION_OBJECT* pobTran) {
    int inResult = VS_SUCCESS;
    long lnDBWhat = DB_FIRST;

    lnDBWhat = DB_FIRST;  /* reset search param to begining of file */

    if (inGetApplicationType() == RESTAURANT)
        inSelect = obDisp.inDO_ChooseOne(NULL, pchGetMsg(RETRIEVE_BY_MSG15), pchGetMsg(RES_SEARCH_OPTION_MSG), 4, NULL_PFI);
    else
        inSelect = obDisp.inDO_ChooseOne(NULL, pchGetMsg(RETRIEVE_BY_MSG15), pchGetMsg(RET_SEARCH_OPTION_MSG), 4, NULL_PFI);

    if (inSelect == VS_ESCAPE)
        inResult = VS_ABORT;
    else
        switch (inSelect) {
        case 1:
            /* Clerk */

#ifdef CLERK_DEFINED

            if (inGetClerkMode() == NO_CLERK) {
                vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
                inResult = VS_ABORT;
            } else {
                if ((inResult = inGetClerkServerId(pobTran)) == VS_SUCCESS)
                    inResult = inGetDCKeyBatchRec(pobTran, KEY_SVR_ID, &pobTran->srBKey, lnDBWhat);
            }
#else

            vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
            inResult = VS_ABORT;

#endif
            break;

        case 2:
            /* Amount */
            if ((inResult = inGetTotalAmount(pobTran)) == VS_SUCCESS)
                inResult = inGetDCKeyBatchRec(pobTran, KEY_AMT, &pobTran->srBKey, lnDBWhat);
            break;

        case 3:
            /* Acct # */
            if ((inResult = inGetLastFourAcct(pobTran)) == VS_SUCCESS)
                inResult = inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM, &pobTran->srBKey, lnDBWhat);
            break;

        case 4:
            /* Inv #  */
            pobTran->srBSKey.inKeyIdx = KEY_INV_NUM;
            if ((inResult = inGetInvoiceNumber(pobTran)) == VS_SUCCESS) {
                /*  1)  Retrieve the record in the batch with a specific invoice #
                            2)  Retrieve the last record in the chain if the record found belongs to a linked list
                        */
                inResult = inGetDCInvBatchRec(pobTran, KEY_INV_NUM, lnDBWhat);
            }
            break;

        default:
            vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
            inResult = VS_ABORT;
            break;
        }

    if (inResult != VS_SUCCESS && inResult != VS_ABORT && inResult != VS_ESCAPE) {
        vdDisplayMessageFromFile(NO_MATCH_MSG21, ERROR_MSG);
        vdSGErrorMessage(0L);
    }

    return (inResult);
}

/*********************************************************************************************
* @func static int | inGetReviewOption |
*
*       Prompts for transaction review action.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm BATCH_KEY * | psrBatchKey   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inGetReviewOption(TRANSACTION_OBJECT* pobTran,BATCH_KEY* psrBatchKey,int inKeyPress) {
    signed int inChoice;
    int inResult = VS_SUCCESS;
    long lnSaveHotKeys;

    //pdebug (("--inGetReviewOption--"));
    // Handle passed key, if necessary
    if ((inChoice = inKeyPress) == VS_SUCCESS) {
        lnSaveHotKeys = obDisp.lnChooseOneHotKeys;
        obDisp.lnChooseOneHotKeys = (obDisp.lnChooseOneHotKeys | (long) KM_c);
        inChoice = obDisp.inDO_ChooseOne(NULL, NULL, pchGetMsg(REVIEW_OPTION_MSG5x), 4, NULL_PFI);  
        obDisp.lnChooseOneHotKeys = lnSaveHotKeys;
    }
    // pdebug (("inChoice=%d",inChoice));
    if (inChoice == VS_ESCAPE)
        return(VS_ESCAPE);

    /* Reset flags */
    pobTran->fAdjust = pobTran->fOtherAdjust = pobTran->fTipAdjust = VS_FALSE;
    pobTran->fPreprinted = VS_FALSE; /* bb1 ITO 100 */
    pobTran->fReferral = VS_FALSE;

    /*
     * Load HDT so correct terminal ID gets printed on the receipt.
     */
    /*if (inLoadHostData(inGetCDTHostIndex()) != VS_SUCCESS) ALVARO*/
    if (inLoadHostData(inGetHostHandle()) != VS_SUCCESS)
        return(VS_ERR);

    switch (inChoice) {
    case 1:
        /* Adjust */
        if (inGetClerkMode() != NO_CLERK) {
            /* clerks may adjust their own transactions */
            if (inGetPWSecurityLevel() == ACCESS_WITH_CLERK_PASSWORD && strncmp(srGDS.szClerkIdFromPW, pobTran->srBKey.szClerkId, CLERK_ID_SIZE) != 0) {
                vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
                return(VS_ERR);
            }
        }

        inResult = inGetAdjustOption(pobTran, 0);
        if (inResult != VS_SUCCESS)
            return(VS_ERR);
        break;

    case 2:
        /* Void */
        /* clerks may void their own transactions */
        if (inGetClerkMode() != NO_CLERK) {
            if (inGetPWSecurityLevel() == ACCESS_WITH_CLERK_PASSWORD && strncmp(srGDS.szClerkIdFromPW, pobTran->srBKey.szClerkId, CLERK_ID_SIZE) != 0) {
                vdDisplayMessageFromFile(VOID_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
                return(VS_ERR);
            }
        }
        /* KV1 980408
         *      Load TRT, Set Tran Code to VOID, and Run Engine.
         */
        inLoadTRTRec(pobTran, BATCH_REVIEW_VOID);
        vdSGErrorMessage(0L);                               /* clear error message */
        memset(pobTran->szRespMsg, 0, RESP_MSG_SIZE);       /* clear response message */
        if (!fGetAllowed(pobTran)) {
            vdDisplayMessageFromFile(VOID_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
            return(VS_ERR);
        }

        if (inCheckBannedCardType(pobTran) == VS_ERR)
            return(VS_ERR);

        inGetReceiptTemplate(pobTran);
        vdMakeFooter(pobTran);
        vdSetTransactionCode(pobTran, VOID);
        if ((inResult = inRunEngine(pobTran->srTRTRec.shFieldFuncPtr, pobTran)) != VS_SUCCESS)
            vdVoidAdjustError(pobTran, inResult, VS_FALSE);
        pobTran->fVoidedBatchRec = VS_FALSE;
        inResult = VS_SUCCESS;
        break;

    case 3:
        /* Prev  */
        /*
         * if PRE_COMP set the transaction code to sale so the next
         * record will come from the correct batch.
         */
        if (inGGCode() == PRE_COMP)
            vdSGCode(SALE);

        switch (inSelect) {
        case 1:
            /* Clerk */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_SVR_ID, psrBatchKey, DB_PREVIOUS);
            if (inResult == VS_EOB)
                inGetDCKeyBatchRec(pobTran, KEY_SVR_ID, psrBatchKey, DB_FIRST);
            break;

        case 2:
            /* Amount */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_AMT, psrBatchKey, DB_PREVIOUS);
            if (inResult == VS_EOB)
                inGetDCKeyBatchRec(pobTran, KEY_AMT, psrBatchKey, DB_FIRST);
            break;

        case 3:
            /* Acct # */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM, psrBatchKey, DB_PREVIOUS);
            if (inResult == VS_EOB)
                inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM, psrBatchKey, DB_FIRST);
            break;

        case 4:
            /* Inv # */
            inResult = inGetDCInvBatchRec(pobTran, KEY_ALL_RECS, DB_PREVIOUS);
            break;

        default:
            break;
        }
        break;

    case 4:
        /* Next  */
        /*
         * if PRE_COMP set the transaction code to sale so the next
         * record will come from the correct batch.
         */
        if (inGGCode() == PRE_COMP)
            vdSGCode(SALE);

        switch (inSelect) {
        case 1:
            /* Clerk */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_SVR_ID, psrBatchKey, DB_NEXT);
            break;

        case 2:
            /* Amount */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_AMT, psrBatchKey, DB_NEXT);
            break;

        case 3:
            /* Acct # */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM, psrBatchKey, DB_NEXT);
            break;

        case 4:
            /* Inv # */
            inResult = inGetDCInvBatchRec(pobTran, KEY_ALL_RECS, DB_NEXT);
            break;

        default:
            break;
        }
        break;

    case 7:
        /* Print */

        inGetReceiptTemplate(pobTran);
        vdMakeFooter(pobTran);
        vdBuildReceipt(pobTran);
        pobTran->srBRec.inPrintOption = PRT_MERCH | PRT_DUPLICATE;
        inResult = inRunFormSegments(pobTran, REPRINT_RECEIPT);
        break;

    default:
        break;
    }

    if (inResult != VS_SUCCESS) {
        vdDisplayMessageFromFile(END_OF_BATCH_MSG21, STATUS_MSG);
        vdSGErrorMessage(0L);
        pause(50);
    }

    return (inResult);
}

/*********************************************************************************************
* @func static int | inGetAdjustOption |
*
*       Prompts for transaction adjust action.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm int     | inPreSelect   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inGetAdjustOption(TRANSACTION_OBJECT* pobTran,int inPreSelect) {
#ifdef CLERK_DEFINED
    int inShift;
    char szOldClerkId[CLERK_ID_SIZE + 1];
    char szNewClerkId[CLERK_ID_SIZE + 1];
    char szADTFileName[FILENAME_SIZE + 1] ;
    long lnErrMsg,
    lnNewIdMsg,
    lnOldIdMsg;	
    long lnBaseAmt,
    lnPlusMinus,
    lnTipSale;	
#endif /* CLERK_DEFINED */
    char szDisplayBuffer[DISP_STR_LEN + 1];
    char szLocBuf[2 + 1];
    signed int inChoice;
    int inResult = VS_SUCCESS;
    char szAuthCode[AUTH_CODE_SIZE + 1];
    
    long lnAdjOptionMsg;
   

  

    /** /pdebug (("--inGetAdjustOption--"));*/

    memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));

    if (inGetApplicationType() == RESTAURANT) {
        lnAdjOptionMsg = RES_ADJUST_OPTION_MSG;

#ifdef CLERK_DEFINED
        lnOldIdMsg = SERVER_ID_MSG;
        lnNewIdMsg = NEW_SERVER_ID_MSG16;
        lnErrMsg = INV_SERVER_ERR_MSG21;
#endif
    } else {
        lnAdjOptionMsg = RET_ADJUST_OPTION_MSG;

#ifdef CLERK_DEFINED
        lnOldIdMsg = CLERK_ID_MSG;
        lnNewIdMsg = NEW_CLERK_ID_MSG16;
        lnErrMsg = INV_CLERK_ERR_MSG21;
#endif
    }

    /*
     *      Choice has been pre-selected.
     */
    if (!inPreSelect)
        inChoice = obDisp.inDO_ChooseOne(NULL, pchGetMsg(ADJUST_OPTION_PROMPT), pchGetMsg(lnAdjOptionMsg), 4, NULL_PFI);
    else
        inChoice = inPreSelect;

    if (inChoice == VS_ESCAPE)
        return(VS_ESCAPE);

    /*
     *      Init Tax handling values.
     */
    pobTran->lnOldTaxAmount = pobTran->srBRec.lnTaxAmount;
    pobTran->fTaxAdjust = VS_FALSE;
    memset(pobTran->szRespMsg, 0x00, RESP_MSG_SIZE);
    switch (inChoice) {
    case 1:
        /* Amount */
        inLoadTRTRec(pobTran, ADJUST);
        vdSGErrorMessage(0L); /* clear error message */
        if (!fGetAllowed(pobTran)) {
            vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
            return(VS_ERR);
        }

        if (inCheckBannedCardType(pobTran) == VS_ERR)
            return(VS_ERR);

        /* This must be done before inRunEngine() for ISO inVerifyPIPTransType() to work */
        pobTran->fAdjust = VS_TRUE;
        vdMakeFooter(pobTran);
        if ((inResult = inRunEngine(pobTran->srTRTRec.shFieldFuncPtr, pobTran)) != VS_SUCCESS) {
            vdVoidAdjustError(pobTran, inResult, VS_TRUE);
            return(VS_ERR);
        }

        inResult = VS_SUCCESS;
        break;

    case 2:
        /* Tip */
        inLoadTRTRec(pobTran, TIP_ADJUST);
        vdSGErrorMessage(0L); /* clear error message */
        if (!fGetAllowed(pobTran)) {
            vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
            return(VS_ERR);
        }

        if (inCheckBannedCardType(pobTran) == VS_ERR)
            return(VS_ERR);

        /* This must be done before inRunEngine() for ISO inVerifyPIPTransType() to work */
        pobTran->fTipAdjust = VS_TRUE;
        vdMakeFooter(pobTran);
        if ((inResult = inRunEngine(pobTran->srTRTRec.shFieldFuncPtr, pobTran)) != VS_SUCCESS) {
            vdVoidAdjustError(pobTran, inResult, VS_TRUE);
            return(VS_ERR);
        }

        inResult = VS_SUCCESS;
        break;

    case 3:
        /* Clerk */

#ifdef CLERK_DEFINED

        if (inGetClerkMode() == NO_CLERK) {
            vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
            return(VS_SUCCESS);
        }
        vdGetMessageFromFile(lnOldIdMsg, szDisplayBuffer);
        vdDisplayAt(obDisp.inHomeCol, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
        vdDisplayAt((obDisp.inHomeCol + 1) + inMessageLength(lnOldIdMsg), obDisp.inDetailLine, strlcpy(szOldClerkId, pobTran->srBKey.szClerkId, CLERK_ID_SIZE), CLR_EOL);
        inResult = inEnterWithMessage(lnNewIdMsg, SCROLL_DISPLAY_FALSE, szNewClerkId, INPUT_ALNUMS, CLERK_ID_SIZE, NULL);

        if (inResult >= 0)       /* Check for escape key */
                                    /* Validate new clerk id */
            if ((inResult = inCheckUDTClerkId(szNewClerkId)) == VS_SUCCESS)
                strlcpy(pobTran->srBKey.szClerkId, szNewClerkId, CLERK_ID_SIZE);
            else
                vdDisplayMessageFromFile(lnErrMsg, ERROR_MSG);

        if (inResult == VS_SUCCESS) {
            /* Set inShift from batch record */
            /* Remove amount, tippped sale and tipped refund from old clerk */

            /* shift not used anymore */
            inShift = pobTran->srBKey.chShift - 0x30;

            /* if it is a refund add it back to old clerk and minus from new clerk, if not a refund do the opposite */
            if (fRefundTrans(pobTran))
                lnPlusMinus = 1L;
            else
                lnPlusMinus = -1L;

            /* Set BaseAmt = TotalofTrans - Tip - Tax - CashBak - Surcharge */
            lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTipAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnCashBackAmount - pobTran->srBRec.lnSChgAmount);

            if (pobTran->srBRec.lnTipAmount > 0)
                lnTipSale = lnBaseAmt;
            else
                lnTipSale = 0L;

            inUpdateUTTRecord(pobTran, szOldClerkId, -1, (lnBaseAmt * lnPlusMinus), (pobTran->srBRec.lnTaxAmount * lnPlusMinus), (pobTran->srBRec.lnTipAmount * lnPlusMinus), (fRefundTrans(pobTran) ? 0L : pobTran->srBRec.lnCashBackAmount * lnPlusMinus), (pobTran->srBRec.lnSChgAmount * lnPlusMinus), (lnTipSale * lnPlusMinus));

            /*  Add to New Clerk the opposite of what is done to old clerk */
            lnPlusMinus *= -1L;
            inUpdateUTTRecord(pobTran, szNewClerkId, 1, (lnBaseAmt * lnPlusMinus), (pobTran->srBRec.lnTaxAmount * lnPlusMinus), (pobTran->srBRec.lnTipAmount * lnPlusMinus), (fRefundTrans(pobTran) ? 0L : pobTran->srBRec.lnCashBackAmount * lnPlusMinus), (pobTran->srBRec.lnSChgAmount * lnPlusMinus), (lnTipSale * lnPlusMinus));

            /*
             *      Need to update ADT File with new clerk
             */
            vdGetADTFileName(szADTFileName);
            if (inInsertADTEntry(pobTran->srBKey.szClerkId, szADTFileName) != VS_SUCCESS) {
                vdSGErrorMessage(ADT_FILE_ERR_MSG21);
                return(VS_ERR);
            }

            pobTran->srBRec.lnOldTotalTransactionAmount = pobTran-> srBKey.lnTotalOfTransactionAmount;
            pobTran->srBRec.lnOldTipAmount = pobTran->srBRec.lnTipAmount;
        }
        pobTran->fOtherAdjust = VS_TRUE;

	/* Fix for ATS Bug No 25 in Predator ICICI List  */
	
#else

	 vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
        inResult = VS_ESCAPE;	

	/* Fix for ATS Bug No 25 in Predator ICICI List  */

#endif /* CLERK_DEFINED */
        break;

    case 4:
        /* Approved code  */
        /* If transaction is on-line or a Refund-Offline or an approved FloorLimit
         * do not allow an adjustment of the approval code
         */
        strcpy(szAuthCode, pobTran->srBRec.szAuthCode);
        strcpy(szLocBuf, "FL");
        if ((!pobTran->srBKey.fOffline) || ((pobTran->srBRec.inType == CREDIT_TRAN) && pobTran->srBKey.fOffline) || (strncmp(szAuthCode, szLocBuf, 2) == 0)) {
            vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
            return(VS_ESCAPE);
        }

        inLoadTRTRec(pobTran, APP_ADJST);
        vdSGErrorMessage(0L); /* Clear error message */
        if (!fGetAllowed(pobTran)) {
            vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
            return(VS_ERR);
        }

        if (inCheckBannedCardType(pobTran) == VS_ERR)
            return(VS_ERR);

        /* This must be done before inRunEngine() for ISO inVerifyPIPTransType() to work */
        pobTran->fOtherAdjust = VS_TRUE;
        if ((inResult = inRunEngine(pobTran->srTRTRec.shFieldFuncPtr, pobTran)) != VS_SUCCESS) {
            vdVoidAdjustError(pobTran, inResult, VS_TRUE);
            return(VS_ERR);
        }
        break;

    default:
        break;
    }
    if (inResult >= 0) {
        pobTran->fAdjustedBatchRec = VS_FALSE;
        /*      pj1 970721
         *      if clerk id was adjusted, update batch record with new clerk id
         *      instead of calling inUpdateBatchAccum which updates UDT record again
         */

	/* Fix for ATS Bug No 25 in Predator ICICI List  */

	#ifdef  CLERK_DEFINED 
        	if (inChoice == 3) /* Clerk  */ 
		{
            		strlcpy(pobTran->srBKey.szClerkId, szNewClerkId, CLERK_ID_SIZE);
            		inUpdateBatch(pobTran);
        	}
	#endif  /* CLERK_DEFINED */

	/* Fix for ATS Bug No 25 in Predator ICICI List  */

    }
    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func static int | inTipAdjust |
*
*           Initiate tip adjust process
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inTipAdjust(TRANSACTION_OBJECT* pobTran) {
    int inResult,
    inOperationCode;
    BATCH_KEY srBatchKey;

    /** /pdebug(("--inTipAdjust--"));*/

    inOperationCode = TIP_ADJUST_OPERATION;
    vdSGOpCode(inOperationCode);

    if (fBatchEmpty(pobTran, VS_FALSE) == VS_TRUE) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, ERROR_MSG);
        return (VS_ERR);
    }

    do {
        do {
            vdDispMsgAt(ADD_TIP_OFFLINE_MSG, obDisp.inHomeCol, obDisp.inTitleLine, CLR_EOL);
            inResult = inTipBatch(pobTran);
            if (inResult == VS_ABORT) {
                vdSGErrorMessage(0L);
                return(VS_ESCAPE);
            }
        } while (inResult != VS_SUCCESS);

        memcpy(&srBatchKey, &pobTran->srBKey, sizeof(BATCH_KEY));

        do {
            int inKeyPress;

            inKeyPress = inDisplayReviewRec(pobTran, pchGetMsg(EXPRESS_TIP_MENU_MSG5x), 4);
            inResult = inGetTipOption(pobTran, &srBatchKey, inKeyPress);
            /* express tip */
            if (inResult == VS_ABORT) {
                vdSGErrorMessage(0L);
                return(VS_ESCAPE);
            }
        } while (inResult != VS_ESCAPE);
    } while (1);
}

/*********************************************************************************************
* @func int | inTipReviewOperation |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inTipReviewOperation(TRANSACTION_OBJECT* pobTran) {
    /** /pdebug(("--inTipReviewOperation--"));*/
    if (inGetTipProcessing() == TIP_OFF) {
        vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
        return(VS_ESCAPE);
    }
    return(inTipAdjust(pobTran));
}

/*********************************************************************************************
* @func static int | inTipBatch |
*
*       This function prompts user to choose a search path.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inTipBatch(TRANSACTION_OBJECT* pobTran) {
    int     inResult = VS_SUCCESS,
    inSearchKey;

    long lnDBWhat = DB_FIRST;
    /** /pdebug(("--inTipBatch--"));*/

    if (inGetApplicationType() == RESTAURANT)
        inSelect = obDisp.inDO_ChooseOne(NULL, pchGetMsg(RETRIEVE_BY_MSG15), pchGetMsg(RES_SEARCH_OPTION_MSG), 4, NULL_PFI);
    else
        inSelect = obDisp.inDO_ChooseOne(NULL, pchGetMsg(RETRIEVE_BY_MSG15), pchGetMsg(RET_SEARCH_OPTION_MSG), 4, NULL_PFI);


    if (inGetPWSecurityLevel() == ACCESS_WITH_CLERK_PASSWORD) {
        inSearchKey = KEY_SVR_ID;
        strlcpy(pobTran->srBKey.szClerkId, srGDS.szClerkIdFromPW, CLERK_ID_SIZE);
    } else
        inSearchKey = 0x0000;

    if (inSelect == VS_ESCAPE)
        inResult = VS_ABORT;
    else {
        inResult = VS_ERROR;
        switch (inSelect) {
        case 1:
            /* Clerk */
            if (inGetClerkMode() == NO_CLERK) {
                vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
                inResult = VS_ABORT;
            } else {
#ifdef CLERK_DEFINED
                inResult = VS_SUCCESS;
                if (inGetPWSecurityLevel() != ACCESS_WITH_CLERK_PASSWORD)
                    inResult = inGetClerkServerId(pobTran);

                if (inResult == VS_SUCCESS)
                    inResult = inGetDCKeyBatchRec(pobTran, KEY_SVR_ID, &pobTran->srBKey, DB_FIRST);
#else
                vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
                inResult = VS_ABORT;
#endif
            }
            break;

        case 2:
            /* Amount */
            if ((inResult = inGetTotalAmount(pobTran)) == VS_SUCCESS)
                inResult = inGetDCKeyBatchRec(pobTran, KEY_AMT + inSearchKey, &pobTran->srBKey, DB_FIRST);
            break;

        case 3:
            /* Acct # */
            if ((inResult = inGetLastFourAcct(pobTran)) == VS_SUCCESS)
                inResult = inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM + inSearchKey, &pobTran->srBKey, DB_FIRST);
            break;

        case 4:
            /* Inv #  */
            if ((inResult = inGetInvoiceNumber(pobTran)) == VS_SUCCESS) {
                /*  1)  Retrieve the record in the batch with a specific invoice #
                            2)  Retrieve the last record in the chain if the record found belongs to a linked list
                        */
                inResult = inGetDCInvBatchRec(pobTran, KEY_INV_NUM, lnDBWhat);
            }
            break;

        default:
            vdDisplayMessageFromFile(TRANS_NOT_SUPPORTED_MSG, ERROR_MSG);
            inResult = VS_ABORT;
            break;
        }
    }

    if (inResult != VS_SUCCESS && inResult != VS_ABORT && inResult != VS_ESCAPE)
        vdDisplayErrorMessage(lnGGErrorMessage());

    return (inResult);
}

/*********************************************************************************************
* @func static int | inGetTipOption |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm BATCH_KEY * | psrBatchKey   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inGetTipOption(TRANSACTION_OBJECT* pobTran,BATCH_KEY* psrBatchKey,int inKeyPress) {
    /* Vinaya HS - Fix for Bug N29 */

#ifdef SHOW_COMPRESSED_MENU

    signed int inChoice;
    int inResult = VS_SUCCESS;
    int inSearchKey;

    /**/pdebug(("--inGetTipOption--"));/**/
    // Handle passed key, if necessary
    if ((inChoice = inKeyPress) == VS_SUCCESS)
        do {
            inChoice = obDisp.inDO_ChooseOne(NULL, NULL, pchGetMsg(ETSL_TIP_MENU_MSG), 2, NULL_PFI);

            if (inChoice == VS_ESCAPE)
                return(VS_ESCAPE);
            //pdebug (("inChoice=%d",inChoice));
        } while (inChoice != KEY_ADJ && inChoice != KEY_PREV); /* express tip */        

        /* Reset flags */
    pobTran->fPreprinted = VS_FALSE;
    pobTran->fAdjust = pobTran->fOtherAdjust = pobTran->fTipAdjust = VS_FALSE;

    /*
     * Load HDT so correct terminal ID gets printed on the receipt.
     */
    /*if (inLoadHostData(inGetCDTHostIndex()) != VS_SUCCESS) ALVARO*/
    if (inLoadHostData(inGetHostHandle()) != VS_SUCCESS)
        return(VS_ERR);

    switch (inChoice) {
    case KEY_ADJ:
        /* Adjust Tip*/
        if (inGetClerkMode() != NO_CLERK) {
            /* Clerks may adjust their own transactions */
            if (inGetPWSecurityLevel() == ACCESS_WITH_CLERK_PASSWORD && strncmp(srGDS.szClerkIdFromPW, pobTran->srBKey.szClerkId, CLERK_ID_SIZE) != 0) {
                vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
                return(VS_ERR);
            }
        }
        inLoadTRTRec(pobTran, TIP_ADJUST);
        vdSGErrorMessage(0L); /* Clear error message */
        if (!fGetAllowed(pobTran)) {
            vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
            return(VS_ERR);
        }
        if (inCheckBannedCardType(pobTran) == VS_ERR)
            return(VS_ERR);

        /* This must be done before inRunEngine() for ISO inVerifyPIPTransType() to work */
        pobTran->fTipAdjust = VS_TRUE;
        vdMakeFooter(pobTran);

        if ((inResult = inRunEngine(pobTran->srTRTRec.shFieldFuncPtr, pobTran)) != VS_SUCCESS) {
            vdVoidAdjustError(pobTran, inResult, VS_TRUE);
            return(VS_ERR);
        } else
            pobTran->fTipAdjust = VS_TRUE;

        inResult = VS_SUCCESS;

        break;

    default:
        inResult = VS_ABORT;
        break;
    }

    if (inResult != VS_SUCCESS && inResult != VS_ABORT) {
        vdDisplayMessageFromFile(END_OF_BATCH_MSG21, STATUS_MSG);
        vdSGErrorMessage(0L);
        pause(50);
    }

    return (inResult);

#else

    signed int inChoice;
    int inResult = VS_SUCCESS;
    int inSearchKey;

    /**/pdebug(("--inGetTipOption--"));/**/
    // Handle passed key, if necessary
    if ((inChoice = inKeyPress) == VS_SUCCESS)
        do {
            inChoice = obDisp.inDO_ChooseOne(NULL, NULL, pchGetMsg(EXPRESS_TIP_MENU_MSG5x), 4, NULL_PFI);
            if (inChoice == VS_ESCAPE)
                return(VS_ESCAPE);
            //pdebug (("inChoice=%d",inChoice));
        } while (inChoice != KEY_ADJ && inChoice != KEY_NEXT && inChoice != KEY_PREV && inChoice != KEY_EXIT); /* express tip */        

        /* Reset flags */
    pobTran->fPreprinted = VS_FALSE;
    pobTran->fAdjust = pobTran->fOtherAdjust = pobTran->fTipAdjust = VS_FALSE;

    /*
     * Load HDT so correct terminal ID gets printed on the receipt.
     */
    /*if (inLoadHostData(inGetCDTHostIndex()) != VS_SUCCESS) ALVARO*/
    if (inLoadHostData(inGetHostHandle()) != VS_SUCCESS)
        return(VS_ERR);

    switch (inChoice) {
    case KEY_ADJ:
        /* Adjust Tip*/
        if (inGetClerkMode() != NO_CLERK) {
            /* Clerks may adjust their own transactions */
            if (inGetPWSecurityLevel() == ACCESS_WITH_CLERK_PASSWORD && strncmp(srGDS.szClerkIdFromPW, pobTran->srBKey.szClerkId, CLERK_ID_SIZE) != 0) {
                vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
                return(VS_ERR);
            }
        }
        inLoadTRTRec(pobTran, TIP_ADJUST);
        vdSGErrorMessage(0L); /* Clear error message */
        if (!fGetAllowed(pobTran)) {
            vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
            return(VS_ERR);
        }
        if (inCheckBannedCardType(pobTran) == VS_ERR)
            return(VS_ERR);

        /* This must be done before inRunEngine() for ISO inVerifyPIPTransType() to work */
        pobTran->fTipAdjust = VS_TRUE;
        vdMakeFooter(pobTran);

        if ((inResult = inRunEngine(pobTran->srTRTRec.shFieldFuncPtr, pobTran)) != VS_SUCCESS) {
            vdVoidAdjustError(pobTran, inResult, VS_TRUE);
            return(VS_ERR);
        } else
            pobTran->fTipAdjust = VS_TRUE;

        inResult = VS_SUCCESS;

        break;

    case KEY_PREV:
        /* Previous */
        if (inGetPWSecurityLevel() == ACCESS_WITH_CLERK_PASSWORD) {
            inSearchKey = KEY_SVR_ID;
            strlcpy(psrBatchKey->szClerkId, srGDS.szClerkIdFromPW, CLERK_ID_SIZE);
        } else
            inSearchKey = 0x0000;
        switch (inSelect) {
        case 4:
            /* Inv # */
            if (inGetPWSecurityLevel() != ACCESS_WITH_CLERK_PASSWORD) {
                inResult = inGetDCInvBatchRec(pobTran, KEY_ALL_RECS, DB_PREVIOUS);
                break;
            }
        case 1:
            /* Clerk */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_SVR_ID, psrBatchKey, DB_PREVIOUS);
            if (inResult == VS_EOB)
                inGetDCKeyBatchRec(pobTran, KEY_SVR_ID, psrBatchKey, DB_FIRST);
            break;

        case 2:
            /* Amount */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_AMT + inSearchKey, psrBatchKey, DB_PREVIOUS);
            if (inResult == VS_EOB)
                inGetDCKeyBatchRec(pobTran, KEY_AMT + inSearchKey, psrBatchKey, DB_FIRST);
            break;

        case 3:
            /* Acct # */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM + inSearchKey, psrBatchKey, DB_PREVIOUS);
            if (inResult == VS_EOB)
                inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM + inSearchKey, psrBatchKey, DB_FIRST);
            break;

        default:
            break;
        }
        break;

    case KEY_NEXT:
        /* Next */
        if (inGetPWSecurityLevel() == ACCESS_WITH_CLERK_PASSWORD) {
            inSearchKey = KEY_SVR_ID;
            strlcpy(psrBatchKey->szClerkId, srGDS.szClerkIdFromPW, CLERK_ID_SIZE);
        } else
            inSearchKey = 0x0000;
        switch (inSelect) {
        case 4:
            /* Inv # */
            if (inGetPWSecurityLevel() != ACCESS_WITH_CLERK_PASSWORD) {
                inResult = inGetDCInvBatchRec(pobTran, KEY_ALL_RECS, DB_NEXT);
                break;
            }
        case 1:
            /* Clerk */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_SVR_ID, psrBatchKey, DB_NEXT);
            break;

        case 2:
            /* Amount */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_AMT + inSearchKey, psrBatchKey, DB_NEXT);
            break;

        case 3:
            /* Acct # */
            inResult = inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM + inSearchKey, psrBatchKey, DB_NEXT);
            break;

        default:
            break;
        }
        break;

        /* express tip */
    case KEY_EXIT:
        inResult = VS_ABORT;
        break;

    default:
        break;
    }

    if (inResult != VS_SUCCESS && inResult != VS_ABORT) {
        vdDisplayMessageFromFile(END_OF_BATCH_MSG21, STATUS_MSG);
        vdSGErrorMessage(0L);
        pause(50);
    }

    return (inResult);

#endif

    /* Vinaya HS - Fix for Bug N29 */
}

/*********************************************************************************************
* @func int | inBatchReviewTipAdjust |
*
*       The tip amount is adjusted from the batch review function.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inBatchReviewTipAdjust(TRANSACTION_OBJECT* pobTran) {
    char szAmount[AMT_SIZE + 1];
    char* szDisplaySymbol;
    char szDisplayBuffer[DISP_STR_LEN + 1];
    long lnBaseAmt;
    long lnTipAmt;
    int inResult;

    szAmount[0] = '\0';
    memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));

    /* pj1 save old amount first */
    pobTran->srBRec.lnOldTotalTransactionAmount = pobTran->srBKey.lnTotalOfTransactionAmount;
    pobTran->srBRec.lnOldTipAmount = pobTran->srBRec.lnTipAmount;
    pobTran->lnOldTaxAmount = pobTran->srBRec.lnTaxAmount;  //PE501 Save original Tax amount too, otherwise it will be zero'd out when adjust failed  CY1

    /* Display old tip amount */
    sprintf(szAmount, SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
    vdFormatAmount(szAmount, VS_FALSE);
    vdTrimLeadSpaces(szAmount);
    vdGetMessageFromFile(TIP_AMOUNT_MSG, szDisplayBuffer);

    vdDisplayAt(obDisp.inHomeCol, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
    vdDispStrAtRight(szAmount, obDisp.inDetailLine, NO_CLEAR);

    /* Prompt for new tip amount */
    vdGetMessageFromFile(NEW_TIP_AMT_MSG, szDisplayBuffer);

    vdGetMessageFromFile(O3200_NEW_TIP_AMT_MSG, szDisplayBuffer);

    //    BT_TRACE ('I', szDisplayBuffer);
    do {
        szAmount[0] = '\0';
        vdDisplayAt(obDisp.inHomeCol, obDisp.inInputLine, szDisplayBuffer, CLR_EOL);
        szDisplaySymbol = szGetCurSymbol();
        inResult = inGetAmount(szAmount, VS_TRUE, 0L, 999999999L, szDisplaySymbol);
        if (inResult >= 0) {
            lnTipAmt = atol(szAmount);

            if (fExcessiveTip(pobTran, lnTipAmt)) {
                // Must use these four lines of code below instead of
                // vdDisplayMessageFromFile(TOO_MUCH_TIP_MSG, ERROR_MSG);
                // because its logic doesn't return a value if the Clear Key
                // is pressed and we need to know so that the transaction
                // doesn't get approved if they pressed clear and are successful
                // in the inGetPwdFromUser() (i.e. no password prompt) because
                // they already logged in here with the Manager password.
                vdDisplayMessageFromFile(TOO_MUCH_TIP_MSG, STATUS_MSG);
                vdBeep();
                vdFlushKeyboardBuffer();
                inResult = inWaitKey(inGetIdleTimeOut());

                if (inResult != KEY_CANCEL) {
                    if (inGetPwdFromUser(ACCESS_WITH_MANAGER_PASSWORD, NO_PIT_INDEX) != VS_ESCAPE) {
                        lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount);
                        pobTran->srBRec.lnTipAmount = atol(szAmount);
                        pobTran->srBKey.lnTotalOfTransactionAmount = lnBaseAmt + pobTran->srBRec.lnTipAmount + pobTran->srBRec.lnTaxAmount;
                        inResult = VS_SUCCESS;
                    } /* end if require manager password */
                    else {
                        inResult = VS_ESCAPE;
                        break;
                    }
                } /* end if not clear key */
                else {
                    // Try again
                    clrscr();
                    continue;
                }
            } /* end if excessive tip */
            else {
                lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount);
                pobTran->srBRec.lnTipAmount = atol(szAmount);
                pobTran->srBKey.lnTotalOfTransactionAmount = lnBaseAmt + pobTran->srBRec.lnTipAmount + pobTran->srBRec.lnTaxAmount;
                inResult = VS_SUCCESS;
            } /* end else not excessive tip */
        } /* end if tip amount entry success */
        else
            break;
    } while (inResult != VS_SUCCESS && !act_kbd_pending_test(KEY_CANCEL));


    return (inResult);
}

/*********************************************************************************************
* @func static void | vdVoidAdjustError |
*
*       Un-Do Void actions and process transaction error.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm int                     | inResult  |
* @parm VS_BOOL                 | fIsItAdjust   |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

static void vdVoidAdjustError(TRANSACTION_OBJECT* pobTran,int inResult,VS_BOOL fIsItAdjust) {
    char szRespMsg[RESP_MSG_SIZE + 1];

    if (fIsItAdjust == VS_TRUE)
        vdUndoAdjustBatchRec(pobTran);
    else
        vdUndoVoidBatchRec(pobTran);

    /*
     *      Process Errors
     */
    if (inResult != VS_ESCAPE) {
        vdClearNonTitleLines();
        if (lnGGErrorMessage())
            vdDisplayErrorMessage(lnGGErrorMessage());
        else {
            vdGGRespMsg(szRespMsg);
            if (strlen(szRespMsg) > 0)
                vdDisplayResponseString(szRespMsg);
        }
    }
}

/*********************************************************************************************
* @func int | inConfirmInvAmt |
*
*       asks the user to confirm the amount of the selected invoice.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inConfirmInvAmt(TRANSACTION_OBJECT* pobTran) {
    signed int inAnswer;
    long lnDBWhat = DB_FIRST;
    long lnInvNum;
    int inEndOfBatch = 0;
    int inResult;
    int inCode  ;
    int inKey   ;
    char* chNull = 0;

    /** /pdebug(("--inConfirmInvAmt--"));*/
    /*
     *      Save Original Transaction Code and Invoice Number
     */
    inCode = pobTran->srBRec.inCode;
    lnInvNum = pobTran->srBKey.lnInvNum;

    for (; ;) {
        if (!inEndOfBatch) {
            inAnswer = (signed char) inDisplayReviewRec(pobTran, pchGetMsg(YESNONEXT_MSG5x), 3);
            if (inAnswer == VS_SUCCESS)
                inAnswer = obDisp.inDO_ChooseOne(chNull, chNull, (char *) pchGetMsg(YESNONEXT_MSG5x), 3, NULL_PFI);
            lnDBWhat = DB_NEXT;
            inKey = KEY_ALL_RECS;
        } else  /* End of Batch - Retrieve the first record again */ {
            inAnswer = VS_EOB;
            lnDBWhat = DB_FIRST;
            inKey = KEY_INV_NUM;

            pobTran->srBKey.lnInvNum = lnInvNum;
        }

        if (inAnswer == VS_ESCAPE || inAnswer == KEY_NO) {
            vdSGErrorMessage(0L);
            return(VS_ESCAPE);
        } else if (inAnswer == KEY_YES)
            break;
        else {
            switch (pobTran->srBSKey.inKeyIdx) {
            case KEY_INV_NUM:
                for (; ;) {
                    if ((inCode == PRE_COMP && pobTran->inOperationCode == PRECOMP_OPERATION) || pobTran->inOperationCode == OPENTAB_DEL_OPERATION) {
                        if ((inResult = inGetOTInvBatchRec(pobTran, inKey, lnDBWhat)) != VS_SUCCESS)
                            break;
                    } else if ((inResult = inGetDCInvBatchRec(pobTran, inKey, lnDBWhat)) != VS_SUCCESS)
                        break;

                    if (pobTran->srBRec.lnForwardLinkInvNum != 0L)
                        continue;

                    if (lnValidateVoidsAndAdjusts(pobTran) == 0L)
                        break;
                }
                break;

            case KEY_ACC_NUM:
                for (; ;) {
                    if ((inCode == PRE_COMP && pobTran->inOperationCode == PRECOMP_OPERATION) || pobTran->inOperationCode == OPENTAB_DEL_OPERATION) {
                        if ((inResult = inGetOTKeyBatchRec(pobTran, KEY_ACC_NUM, &pobTran->srBKey, lnDBWhat)) != VS_SUCCESS)
                            break;
                    } else if ((inResult = inGetDCKeyBatchRec(pobTran, KEY_ACC_NUM, &pobTran->srBKey, lnDBWhat)) != VS_SUCCESS)
                        break;

                    if (pobTran->srBRec.lnForwardLinkInvNum != 0L)
                        continue;

                    if (lnValidateVoidsAndAdjusts(pobTran) == 0L)
                        break;
                    else if (lnDBWhat == DB_FIRST)
                        lnDBWhat = DB_NEXT;
                }
                break;

            case KEY_AMT:
                for (; ;) {
                    if ((inCode == PRE_COMP && pobTran->inOperationCode == PRECOMP_OPERATION) || pobTran->inOperationCode == OPENTAB_DEL_OPERATION)
                        inResult = inGetOTKeyBatchRec(pobTran, KEY_AMT, &pobTran->srBKey, lnDBWhat);
                    else
                        inResult = inGetDCKeyBatchRec(pobTran, KEY_AMT, &pobTran->srBKey, lnDBWhat);
                    if (pobTran->srBRec.lnForwardLinkInvNum != 0L)
                        continue;

                    if (lnValidateVoidsAndAdjusts(pobTran) == 0L)
                        break;
                }
                break;

#ifdef CLERK_DEFINED
            case KEY_SVR_ID:
                for (; ;) {
                    if ((inCode == PRE_COMP && pobTran->inOperationCode == PRECOMP_OPERATION) || pobTran->inOperationCode == OPENTAB_DEL_OPERATION)
                        inResult = inGetOTKeyBatchRec(pobTran, KEY_SVR_ID, &pobTran->srBKey, lnDBWhat);
                    else
                        inResult = inGetDCKeyBatchRec(pobTran, KEY_SVR_ID, &pobTran->srBKey, lnDBWhat);
                    if (pobTran->srBRec.lnForwardLinkInvNum != 0L)
                        continue;

                    if (lnValidateVoidsAndAdjusts(pobTran) == 0L)
                        break;
                }
                break;
#endif


            default:
                vdSGErrorMessage(NO_MATCH_MSG21);
                return(VS_ERR);
            }

            if (inResult != VS_SUCCESS) {
                vdDisplayMessageFromFile(END_OF_BATCH_MSG21, WARNING_MSG);
                vdSGErrorMessage(0L);
                inEndOfBatch = 1;
            } else
                inEndOfBatch = 0;
        }
    }
    return(VS_SUCCESS);
}
/*********************************************************************************************
* @func int | inVoidChoice |
*
*       This function prompts user to choose which search path
*       they want for VOID - Invoice number or last 5 digits of
*       account number.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
* @end
**********************************************************************************************/

int inVoidChoice(TRANSACTION_OBJECT* pobTran) {
    signed int inAnswer;
    long lnMsg;

    inAnswer = obDisp.inDO_ChooseOne(NULL, (char *) pchGetMsg(VOID_PREVIOUS_MSG15), (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);
    if (inAnswer == VS_ESCAPE) {
        vdSGErrorMessage(0L);
        return(VS_ESCAPE);
    } else if (inAnswer == KEY_YES) {
        if (inGetDCKeyBatchRec(pobTran, KEY_ALL_RECS, &pobTran->srBKey, DB_LAST) != VS_SUCCESS) {
            vdDisplayErrorMessage(NO_MATCH_MSG21);
            return(VS_ERROR);
        }
        /*  1)  Retrieve the last record in the batch
                */
        if ((lnMsg = lnValidateVoidsAndAdjusts(pobTran)) == 0L) {
            pobTran->srBSKey.inKeyIdx = KEY_INV_NUM;
            return(VS_SUCCESS);
        } else {
            vdDisplayErrorMessage(lnMsg);
            return(VS_ERROR);
        }
    } else
        return (inUserChoice(pobTran));
}

/* -------------------------------------------------------------------------------------------------------- */

static int inDefaultRetrieveBatchInvOrAcct(TRANSACTION_OBJECT *pobTran, int (*pfGetXXKeyBatchRec )(TRANSACTION_OBJECT*, int, BATCH_KEY*, long),
											int (*pfGetXXInvBatchRec) (TRANSACTION_OBJECT*, int, long))
{
    signed int inAnswer;
    long lnMsg;
    long lnDBWhat = DB_FIRST;
    int inRetVal;
    char* chNull = 0;

    if (!pfGetXXKeyBatchRec)
        return(VS_ESCAPE);  /* "inGetXXKeyBatchRec" not defined */
    if (!pfGetXXInvBatchRec)
        return(VS_ESCAPE);  /* "inGetXXInvBatchRec" not defined */

    do {
        inAnswer =  obDisp.inDO_ChooseOne(chNull, (char *) pchGetMsg(RETRIEVE_BY_MSG15), (char *) pchGetMsg(INV_ACCT_CHOICE_MSG5x), 2, NULL_PFI);

        if (inAnswer == VS_ESCAPE)
            return(VS_ERR);
        else if (inAnswer == CHOICE_INV)
            for (; ;) {
		  pobTran->srBSKey.inKeyIdx = KEY_INV_NUM;
                if ((inRetVal = inGetInvoiceNumber(pobTran)) != VS_SUCCESS) {
                    inRetVal = VS_ERR;
                    break;
                }
                /*  1)  Retrieve the record in the batch with a specific invoice #
                            2)  Retrieve the last record in the chain if the record found belongs to a linked list
                        */
                if ((inRetVal = pfGetXXInvBatchRec(pobTran, KEY_INV_NUM, lnDBWhat)) != VS_SUCCESS) {
                    vdDisplayErrorMessage(NO_MATCH_MSG21);
                    continue;
                }
                if ((lnMsg = lnValidateVoidsAndAdjusts(pobTran)) == 0L)
                    break;
                else
                    vdDisplayErrorMessage(lnMsg);
            }
        else if (inAnswer == CHOICE_ACCT)
            do {
                if ((inRetVal = inGetLastFourAcct(pobTran)) != VS_SUCCESS) {
                    inRetVal = VS_ERR;
                    break;
                }
                for (lnMsg = NO_MATCH_MSG21; lnMsg != 0L; lnDBWhat = DB_NEXT) {
                    if ((inRetVal = pfGetXXKeyBatchRec(pobTran, KEY_ACC_NUM, &pobTran->srBKey, lnDBWhat)) != VS_SUCCESS) {
                        vdDisplayErrorMessage(lnMsg);
                        break;
                    }
                    lnMsg = lnValidateVoidsAndAdjusts(pobTran);

                    /* If the first Acct # found is invalid keep trying next until EOF */
                }
            } while (lnMsg != 0L);
    } while (inRetVal == VS_ERROR || inRetVal == VS_ESCAPE);

    return(inRetVal);
}


static int (*inRetrieveBatchInvOrAcct)(TRANSACTION_OBJECT*,int (*) (TRANSACTION_OBJECT *, int, BATCH_KEY *, long),int   (*) (TRANSACTION_OBJECT *, int, long))   =  inDefaultRetrieveBatchInvOrAcct;

void vdOverLoadRetrieveBatchInvOrAcct(int (*inNewRetrieveBatchInvOrAcct) ()) {
    inRetrieveBatchInvOrAcct = inNewRetrieveBatchInvOrAcct;
}
/*********************************************************************************************
* @func int | inRetrieveInvOrAcct |
*
*       This function prompts user to choose which search path
*       they want for OPENTAB - Invoice number or last 5 digits of
*       account number.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
* @end
**********************************************************************************************/

int inRetrieveInvOrAcct(TRANSACTION_OBJECT* pobTran) {
    return (inRetrieveBatchInvOrAcct(pobTran, inGetOTKeyBatchRec, inGetOTInvBatchRec));
}

/*********************************************************************************************
* @func int | inUserChoice |
*
*       This function prompts user to choose which search path
*       they want for VOID - Invoice number or last 5 digits of
*       account number.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
* @end
**********************************************************************************************/

int inUserChoice(TRANSACTION_OBJECT* pobTran) {
    return (inRetrieveBatchInvOrAcct(pobTran, inGetDCKeyBatchRec, inGetDCInvBatchRec));
}

/*********************************************************************************************
* @func int | inSameCardConfirm |
*
*       This function prompts user to confirm same card is used
*       for Close Tab processing.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inSameCardConfirm(TRANSACTION_OBJECT* pobTran) {
    signed int inAnswer;
    char szDate[DATE_SIZE + 1],
    szTime[TIME_SIZE + 1];
    char* pchMesg = (char*) 0;
    char* chNull = 0;

    /** /pdebug(("--inSameCardConfirm--"));*/
    /*
     *      Perform Close Tab Batch Record Maintenance.
     */
    pobTran->lnOTInvNum = pobTran->srBKey.lnInvNum;
    pobTran->srBRec.fCloseTabSameCard = VS_TRUE;
    pobTran->srBRec.inCode = PRE_COMP;
    pobTran->srBKey.fOffline = fGetOffline(pobTran);
    pobTran->srBRec.lnMessage = PRE_COMP_MSG;
    strcpy(pobTran->srBRec.szTranAbbrev, pobTran->srTRTRec.TranAbbrev);

    if (!(fGetSameCardConfirm())) {
        inInitPrintOption(pobTran);
        return(VS_SUCCESS);
    }

    pchMesg = (char *) pchGetMsg(SAME_CARD_MSG15);

    inAnswer = (char) obDisp.inDO_ChooseOne(chNull, pchMesg, (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);

    if (inAnswer == KEY_YES)   /* Don't check floor limit on same card */ {
        inInitPrintOption(pobTran);
        vdSetCheckFloorLimit(pobTran, VS_FALSE);
    }

    if (inAnswer == VS_ESCAPE)
        return(VS_ESCAPE);
    else if (inAnswer == KEY_NO) {
        vdGetDate(szDate, MMDDYY);
        strcpy(pobTran->srBRec.szDate, szDate);
        vdGetTime(szTime);
        strcpy(pobTran->srBRec.szTime, szTime);

        /* Save Orig. Open Tab's Acct No. */
        pobTran->lnOTAcctNum = str2long(&pobTran->srBRec.szPAN[strlen(pobTran->srBRec.szPAN) - LAST4_DIGIT_ACCT]);

        MEMCLR(pobTran->srBRec.stT1Data, TRACK1_SIZE + 1);
        MEMCLR(pobTran->srBRec.stT2Data, TRACK2_SIZE + 1);
        MEMCLR(pobTran->srBRec.szCHolder, CHOLDER_SIZE + 1);
        MEMCLR(pobTran->srBRec.szPAN, PAN_SIZE + 1); 
        pobTran->srBRec.inChipStatus = 0; 
        pobTran->srBRec.fT1Data = VS_FALSE; 
        pobTran->srBRec.fT2Data = VS_FALSE; 
        pobTran->srBRec.fCHolder = VS_FALSE; 

        // Clear out Tax and Cust Num incase Open Tab was a Purchase card
        // and this Close Tab is not
        pobTran->srBRec.lnTaxAmount = 0;
        MEMCLR(pobTran->srBRec.szCustNum, REF_CUST_SIZE + 1);

        /* Since changing cards, the host may change and therefore the batch will change */
        vdCloseDCBatch(pobTran);

        if (inRunFunction(pobTran, GET_CARD_FIELDS) != VS_SUCCESS)
            return(VS_ERR);

        if (pobTran->inChipStatus == EMV_CARD) {
            if (inRunFunction(pobTran, EMV_CHECK_FALLBACK) != VS_SUCCESS)
                return(VS_ERR);
        }           


        inSelectAndLoadHost(pobTran);

        /* Since card changes, the host may change so open appropriate batch */
        inOpenDCBatch(pobTran);

        /*
         * inLoadDefaultCurrency() loads the correct ACT and TCT files.
         */
        inLoadDefaultCurrency(pobTran);

        // Load the TRT rec again incase the Open Tab was with a 
        // different host than the one we are closing with.
        // BE CAREFUL !!  CONFIRM_SAME_CARD flow item must be in
        // the same spot for all hosts' TRTs or this flow (or another)
        // might get repeated.
        inLoadTRTRec(pobTran, inGGCode());

        if (!fGetAllowed(pobTran)) {
            vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
            return(VS_ERR);
        }

        if (inCheckBannedCardType(pobTran) == VS_ERR)
            return(VS_ERR);

        if (inRunFunction(pobTran, FRAUD_CONTROL) != VS_SUCCESS)
            return(VS_ERR);

        if (inRunFunction(pobTran, IMPRINT_CARD_CONFIRM) != VS_SUCCESS)
            return(VS_ERR);

        if (pobTran->srBRec.inTranCardType == DEBIT_CARD || pobTran->srBRec.inTranCardType == EBT_CARD)
            pobTran->srBRec.lnSChgAmount = (long) inGetSurCharge();


        pobTran->srBKey.lnInvNum = lnGetInvNum();

        pobTran->srBKey.fOffline = VS_FALSE ;
        vdSetOffline(pobTran, VS_FALSE);
        pobTran->srBRec.fCloseTabSameCard = VS_FALSE ;
        pobTran->srBRec.fCloseTabNewCard = VS_TRUE ;
        inInitPrintOption(pobTran);
    } /* end else not same card */

    /* Set floor limit flag to 0 on a same card close tab til
     * the application gets a re-auth transaction.
     */

    if ((pobTran->srBRec.fCloseTabSameCard || pobTran->srBRec.fCloseTabNewCard) && (!fGetSameCardConfirm()))
        vdSetCheckFloorLimit(pobTran, VS_FALSE);

    return (VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inValidateAdjust |
*
*       Checks if the adjust is allowed.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inValidateAdjust(TRANSACTION_OBJECT* pobTran) {
    TRANSACTION_OBJECT obTran;

    /* Load TRT locally for batch record    */
    inLoadTRTRec(&obTran, pobTran->srBRec.inCode);

    /* Check batch record TRT   */
    if ((!obTran.srTRTRec.AdjustAllowed) || (pobTran->srBKey.fVoided)) {
        vdSGErrorMessage(ADJ_NOT_ALLOWED_ERR_MSG);
        return(VS_ERR);
    }

    /* prompt for Man PW when limit is reached. */
    if (pobTran->srBRec.inNumberOfAdjusts + pobTran->srBRec.inNumberOfTipAdjusts >= inGetTipMaxAdjust()) {
        vdDisplayMessageFromFile(EXCEED_ADJ_MAX, WARNING_MSG);
        if (inGetPwdFromUser(ACCESS_WITH_MANAGER_PASSWORD, NO_PIT_INDEX) <= VS_ERR) {
            vdSGErrorMessage(ADJ_NOT_ALLOWED_ERR_MSG);
            return (VS_ERR);
        }
        vdClearStatusMessage();
    }

    return (VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inValidateTipAdjust |
*
*       checks if tip adjust is allowed.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
* @end
**********************************************************************************************/

int inValidateTipAdjust(TRANSACTION_OBJECT* pobTran) {
    TRANSACTION_OBJECT obTran;

    /* Load TRT locally for batch record    */
    inLoadTRTRec(&obTran, pobTran->srBRec.inCode);

    /* Check batch record TRT   */
    if (!obTran.srTRTRec.AdjustAllowed || (pobTran->srBKey.fVoided)) {
        vdClearNonTitleLines();
        vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
        (void) inWaitKey(inGetIdleTimeOut());
        vdSGErrorMessage(0L);
        return(VS_ERR);
    }

    if (inGetTipProcessing() == TIP_OFF) {
        vdClearNonTitleLines();
        vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
        (void) inWaitKey(inGetIdleTimeOut());
        vdSGErrorMessage(0L);
        return(VS_ERR);
    }

    /* kv1 961217 - prompt for Man PW when limit is reached. */
    if (pobTran->srBRec.inNumberOfAdjusts + pobTran->srBRec.inNumberOfTipAdjusts >= inGetTipMaxAdjust()) {
        vdDisplayMessageFromFile(EXCEED_ADJ_MAX, WARNING_MSG);
        if (inGetPwdFromUser(ACCESS_WITH_MANAGER_PASSWORD, NO_PIT_INDEX) <= VS_ERR)
            //      if ( inGetAndValSuperManPwds(MAN_PW) <= VS_ERR )
        {
            vdClearNonTitleLines();
            vdDisplayMessageFromFile(ADJ_NOT_ALLOWED_ERR_MSG, ERROR_MSG);
            (void) inWaitKey(inGetIdleTimeOut());
            vdSGErrorMessage(0L);
            return (VS_ERR);
        }
    }

    return (VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inValidateVoid |
*       Checks if the void is allowed.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
* @end
**********************************************************************************************/

int inValidateVoid(TRANSACTION_OBJECT* pobTran) {
    TRANSACTION_OBJECT obTran;
    /* added to incorporate SPBASE2.5 change of 06/16/99 gw */

    /* This check must be done before loading batch rec TRT */
    if (inCheckBannedCardType(pobTran) == VS_ERR)
        return(VS_ERR);

    /* Load the correct host */
    /*if (inLoadHostData(inGetCDTHostIndex()) != VS_SUCCESS) ALVARO*/
    if (inLoadDefaultHost(inGetHostHandle()) != VS_SUCCESS)
        return(VS_ERR);

    /* Load TRT locally for batch record    */
    inLoadTRTRec(&obTran, pobTran->srBRec.inCode);

    if (pobTran->srBKey.fVoided) {
        vdSGErrorMessage(ALREADY_VOIDED_ERR_MSG);
        return(VS_ERR);
    }

    /* Check batch record TRT   */
    if (!obTran.srTRTRec.VoidAllowed) {
        vdSGErrorMessage(VOID_NOT_ALLOWED_ERR_MSG);
        return(VS_ERR);
    }

    return (VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inSummaryReviewOperation |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ERR
* @end
**********************************************************************************************/

int inSummaryReviewOperation(TRANSACTION_OBJECT* pobTran) {
    //pdebug(("--SummaryReviewOperation--"));
    return(inBatchReview(pobTran));
}

/*********************************************************************************************
* @func static int | inDisplayReviewRec |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

static int inDisplayReviewRec(TRANSACTION_OBJECT* pobTran,char* pszChoices,int inNumChoices) {
    int inRetVal = VS_ERR;
    PFI_TO_PSZ_INT pinFunction;

    if ((pinFunction = inGetFunctionPointer(DISPLAY_REVIEW_REC)) != NULL_PFI)
        inRetVal = pinFunction(pobTran, pszChoices, inNumChoices);

    return (inRetVal);
}

/*********************************************************************************************
* @func int | inDefaultDisplayReviewRec |
*
*       Displays Transaction information during batch review processes.
*
*           NOTE: This function may be overloaded using Field ID: DISPLAY_REVIEW_REC.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |  VS_SUCCESS
* @end
**********************************************************************************************/

int inDefaultDisplayReviewRec(TRANSACTION_OBJECT* pobTran,char* pszChoices,int inNumChoices) {
#ifndef IMAM_REMOVE
    signed int inRetVal = VS_SUCCESS;
    char szAmt[AMT_SIZE + 1];
    char szCardLabel[CLABEL_SIZE + 1];
    char szTransType[TRAN_TYPE_MSG_SIZE + 1];
    char szTransPrefix[TRAN_TYPE_MSG_SIZE + 1];
    char szCentPrefix[21 + 1];
    char szLocBuf[2 + 1];
    char szDisplayBuffer[DISP_STR_LEN + TRAN_TYPE_MSG_SIZE + 1]; /* added trans. type */
    char szPAN[PAN_SIZE + 1];
    int inFontType = 1,
    inGrid,
    inFLen,
    inSLen;  // (1 -> 1 byte address 2 -> 2 byte address )

    /** /pdebug (("--inDispInvTotal--"));*/

    memset(szCardLabel, 0, sizeof(szCardLabel));
    memset(szPAN, 0, sizeof(szPAN));
    memset(szTransType, 0, sizeof(szTransType));
    memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));


    sprintf(szAmt, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount);


    /* Load the correct currency for this record, multi-currency error */
    if (inLoadCSTRec(pobTran->srBKey.inCurrencyIndex) != VS_SUCCESS) {
        vdDisplayMessageFromFile(CST_ERR_MSG, WARNING_MSG);
        return(VS_ERR);
    }
    strcpy(szDisplayBuffer, szGetCurSymbol());

    strcpy(szPAN, pobTran->srBRec.szPAN);

    vdFormatAmount(szAmt, VS_FALSE);
    vdTrimLeadSpaces(szAmt);
    vdGetMessageFromFile(pobTran->srBRec.lnMessage, szTransType);

    inFontType = get_font_mode();

    if (inFontType == 2)  // 2 byte addresssing scheme
    {
        memset(szLocBuf, 0x00, sizeof(szLocBuf));
        szLocBuf[0] = 0x01;
        szLocBuf[1] = 0x20;
        strcat(szDisplayBuffer, szLocBuf);
        // szAmt has the amount already formatted
    } else {
        // Normal messages (1 byte addressing)
        strcpy(szLocBuf, " ");
        strcat(szDisplayBuffer, szLocBuf);
        strcat(szDisplayBuffer, szAmt);

        /* Get trans. type */
        strcat(szDisplayBuffer, szLocBuf);
    }
    memset(szTransPrefix, '\0', TRAN_TYPE_MSG_SIZE);
    if (pobTran->srBKey.fVoided == VS_TRUE) {
        vdGetMessageFromFile(VOID_MSG6, szTransPrefix);
        if (inFontType != 2) // do padding only if normal messages
            pad(szTransPrefix, szTransPrefix, ' ', strlen(szTransPrefix) + 1, LEFT);
    } else if ((pobTran->srBRec.inNumberOfAdjusts > 0) || ((pobTran->srBRec.inNumberOfTipAdjusts > 0) && (pobTran->srBRec.inOrgCode == ADD_TIP_OFFLINE))) {
        vdGetMessageFromFile(ADJUST_MSG6, szTransPrefix);
        if (inFontType != 2) // do padding only if normal messages
            pad(szTransPrefix, szTransPrefix, ' ', strlen(szTransPrefix) + 1, LEFT);
    }

    /* KV1 98/02/04
     *      Update Line 1 with Card type and Operation Type (Batch Review or Tip Adjust)
     *      at once to reduce screen flashing.
     */
    szCardLabel[CLABEL_SIZE] = NULL_CH;

    if (pobTran->srBRec.inTranCardType == DEBIT_CARD)
        vdGetMessageFromFile(DEBIT_MSG, szCardLabel);
    else
        strlcpy(szCardLabel, szGetCardLabel(), CLABEL_SIZE);

    memset(szCentPrefix, NULL_CH, sizeof(szCentPrefix));
    if (inFontType != 2) // do padding only if normal messages
        pad(szCentPrefix, szTransPrefix, ' ', (obDisp.in3200BarCol - 1), CENTER);

    vdClearNonTitleLines();

    inGrid = getgrid();

    if (inGrid == 0)  //16 0r 8 chars
    {
        inMLDisplayAt(obDisp.inHomeCol, 3, szCardLabel, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        inMLDisplayAt(obDisp.inHomeCol, 4, szPAN, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
        vdDisplayAt(obDisp.inHomeCol, 3, szTransType, NO_CLEAR);
        inFLen = strlen(szTransType) / inFontType;
        inSLen = strlen(szTransPrefix) / inFontType;
        if (inSLen > (obDisp.in3200BarCol - inFLen))
            szTransPrefix[((obDisp.in3200BarCol - inFLen) * 2) - 1] = 0X00;
        vdDisplayAt(obDisp.inHomeCol + strlen(szTransType) / inFontType, 3, szTransPrefix, NO_CLEAR);
        vdDisplayAt(obDisp.inHomeCol, 4, szDisplayBuffer, NO_CLEAR);
        inMLDisplayAt(obDisp.in3200BarCol * 2 - 1 - strlen(szAmt), 8, szAmt, NO_CLEAR, ML_USE_GIVEN_FONT, ML_ACTION_FONT, "F:ASC8X21.VFT");
    } else {
        vdDisplayAt(obDisp.inHomeCol, 2, szCardLabel, NO_CLEAR);
        vdDisplayAt(obDisp.inHomeCol, 3, szCentPrefix, NO_CLEAR);
        vdDisplayAt(obDisp.inHomeCol, 4, szTransType, NO_CLEAR);
        vdDisplayAt(obDisp.inHomeCol, 5, szPAN, NO_CLEAR);
        vdDisplayAt(obDisp.inHomeCol, 6, szDisplayBuffer, NO_CLEAR);
    }

#if 0 // KV1 Debug - Test Key Passing code.
    {
    long    lnSaveHotKeys;
    
        lnSaveHotKeys = obDisp.lnChooseOneHotKeys;
        obDisp.lnChooseOneHotKeys = (obDisp.lnChooseOneHotKeys | KM_d);
        inRetVal = obDisp.inDO_ChooseOne(NULL, NULL, pszChoices, inNumChoices, NULL_PFI);   
        obDisp.lnChooseOneHotKeys = lnSaveHotKeys;
    }
#endif  
    return (inRetVal);
#endif //IMAM_REMOVE
	return VS_SUCCESS;
}

long lnDefaultValidateVoidsAndAdjusts(TRANSACTION_OBJECT* pobTran) {
    /** /pdebug (("--lnValidateVoidsAndAdjusts--"));*/

    if (pobTran->srBKey.fVoided)
        return(ALREADY_VOIDED_ERR_MSG);

    if ((pobTran->fAdjust) || (pobTran->fOtherAdjust) && pobTran->srBRec.inNumberOfAdjusts > 0)
        return(ADJ_NOT_ALLOWED_ERR_MSG);

    if ((pobTran->fTipAdjust) && pobTran->srBRec.inNumberOfTipAdjusts > 0)
        return(ALREADY_VOIDED_ERR_MSG);

    return(0L);
}

long (*lnValidateVoidsAndAdjusts)(TRANSACTION_OBJECT*) =  lnDefaultValidateVoidsAndAdjusts;

void vdOverLoadValidateVoidsAndAdjusts(long (*inNewValidateVoidsAndAdjusts) ()) {
    lnValidateVoidsAndAdjusts = inNewValidateVoidsAndAdjusts;
}

int REVIEW_CODE_CHECK(char* a,char* b,short * c,char* d,unsigned char* e) {
    GET_VER(a, b, c, d, e);
    return 1;
}



#undef VSREVIEW_C

#endif // BATCH_DEFINED
